package launch

import (
	"context"
	"strings"
	"sync"
)

type PlaceHolder struct {
	data map[string]string
	ctx  context.Context
	mut  sync.Mutex
}

func NewPlaceHolder() *PlaceHolder {
	p := &PlaceHolder{data: make(map[string]string)}

	p.generateDataByDefault()

	return p
}

func (ph *PlaceHolder) SetContext(ctx context.Context) {
	ph.ctx = ctx
}

func (ph *PlaceHolder) generateDataByDefault() {
	ph.data["auth_player_name"] = ""
	ph.data["version_name"] = ""
	ph.data["game_directory"] = ""
	ph.data["library_directory"] = ""
	ph.data["assets_root"] = ""
	ph.data["assets_index_name"] = ""
	ph.data["auth_uuid"] = ""
	ph.data["auth_access_token"] = ""
	ph.data["clientid"] = ""
	ph.data["auth_xuid"] = ""
	ph.data["user_type"] = ""
	ph.data["version_type"] = "sfLauncher"
	ph.data["resolution_width"] = "854"
	ph.data["resolution_height"] = "480"
	ph.data["natives_directory"] = ""
	ph.data["launcher_name"] = "sfLauncher"
	ph.data["launcher_version"] = "100"
	ph.data["classpath"] = ""
}

func (ph *PlaceHolder) SetAuthPlayerName(name string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["auth_player_name"] = name
}

func (ph *PlaceHolder) GetAuthPlayerName() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["auth_player_name"]
}

func (ph *PlaceHolder) SetVersionName(version string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["version_name"] = version
}

func (ph *PlaceHolder) GetVersionName() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["version_name"]
}

func (ph *PlaceHolder) SetGameDirectory(dir string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["game_directory"] = dir
}

func (ph *PlaceHolder) GetGameDirectory() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["game_directory"]
}

func (ph *PlaceHolder) SetAssetsRoot(assertsRoot string) {
	ph.mut.Lock()
	defer ph.mut.TryLock()

	ph.data["assets_root"] = assertsRoot
}

func (ph *PlaceHolder) GetAssetsRoot() string {
	ph.mut.Lock()
	defer ph.mut.TryLock()

	return ph.data["assets_root"]
}

func (ph *PlaceHolder) SetAssetsIndexName(name string) {
	ph.mut.Lock()
	defer ph.mut.TryLock()

	ph.data["assets_index_name"] = name
}

func (ph *PlaceHolder) GetAssetsIndexName() string {
	ph.mut.Lock()
	defer ph.mut.TryLock()

	return ph.data["assets_index_name"]
}

func (ph *PlaceHolder) SetAuthUuid(uuid string) {
	ph.mut.Lock()
	defer ph.mut.TryLock()

	ph.data["auth_uuid"] = uuid
}

func (ph *PlaceHolder) GetAuthUuid() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["auth_uuid"]
}

func (ph *PlaceHolder) SetAuthAccessToken(token string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["auth_access_token"] = token
}

func (ph *PlaceHolder) GetAuthAccessToken() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["auth_access_token"]
}

func (ph *PlaceHolder) SetClientId(clientId string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["client_id"] = clientId
}

func (ph *PlaceHolder) GetClientId() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["client_id"]
}

func (ph *PlaceHolder) SetAuthXuid(xuid string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["auth_xuid"] = xuid
}

func (ph *PlaceHolder) GetAuthXuid() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["auth_xuid"]
}

func (ph *PlaceHolder) SetUserType(userType string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["user_type"] = userType
}

func (ph *PlaceHolder) GetUserType() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["user_type"]
}

func (ph *PlaceHolder) SetVersionType(versionType string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["version_type"] = versionType
}

func (ph *PlaceHolder) GetVersionType() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["version_type"]
}

func (ph *PlaceHolder) SetResolutionWidth(width string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["resolution_width"] = width
}

func (ph *PlaceHolder) GetResolutionWidth() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["resolution_width"]
}

func (ph *PlaceHolder) SetResolutionHeight(height string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["resolution_herght"] = height
}

func (ph *PlaceHolder) GetResolutionHeight() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["resolution_herght"]
}

func (ph *PlaceHolder) SetNativesDirectory(dir string) {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["natives_directory"] = dir
}

func (ph *PlaceHolder) GetNativesDirectory() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["natives_directory"]
}

// todo
func (ph *PlaceHolder) SetClassPath() {
	builder := strings.Builder{}

	ph.mut.Lock()
	defer ph.mut.Unlock()

	ph.data["classpath"] = builder.String()
}

func (ph *PlaceHolder) GetClassPath() string {
	ph.mut.Lock()
	defer ph.mut.Unlock()

	return ph.data["classpath"]
}
